<template>
	<view class="login-form">
		<tm-sheet :dense="true">
			<tm-images :width="200" :height="200" :round="4" src="../../static/logo.png"></tm-images>
			<tm-sheet color="blue" :shadow="24">
				<view class="text-size-s text-weight-b mb-24">MiniTool</view>
				<tm-sheet :margin="[0,0]" :padding="[0,0]" classname="overflow" :shadow="24">
					<tm-input :required="true" title="账号" v-model="login_form.user_name" placeholder="请输入账号"
						align="right"></tm-input>
					<tm-input :required="true" title="密码" v-model="login_form.passsword" placeholder="请输入密码"
						align="right" input-type="password"></tm-input>
					<tm-input :required="true" title="确认密码" v-model="login_form.passsword1" placeholder="请再次输入密码"
						align="right" input-type="password"></tm-input>
				</tm-sheet>
			</tm-sheet>
			<tm-row class="pt-n10">

				<tm-col :grid="12">
					<tm-button @click="register()">注册</tm-button>
				</tm-col>
			</tm-row>

		</tm-sheet>
		<!-- <tm-sticky model="bottom">
			<tm-sheet >版权所有©本心</tm-sheet>
			</tm-sticky> -->
	</view>

</template>

<script>
	export default {
		data() {
			return {
				login_form: {
					user_name: '',
					passsword: '',
					password1: '',
					auto_login: true
				}
			}
		},
		methods: {
			//登录选择-根据宿主环境选择不同的登录策略
			register() {

				uni.setStorageSync('register_form', this.register_form)

				// #ifdef MP-WEIXIN
				this.WXregister()
				// #endif
				// #ifndef MP-WEIXIN
				this.Appregister()
				// #endif

			},
			/* APP注册逻辑 */
			Appregister() {
				uniCloud.callFunction({
					name: 'uni-id-cf',
					data: {
						action: 'register',
						params: {
							"username": this.login_form.user_name,
							"nickname": "",
							'password': this.login_form.passsword,
							'pwd2': this.login_form.password1
						},
					},
					success: ({
						result
					}) => {
						console.log(result);
						if (result.code === 0) {
							uni.navigateTo({
								url: './login'
							})
						} else {
							uni.showModal({
								content: result.msg,
								showCancel: false
							});
						}
					}
				})
			},
			/* 微信小程序登录逻辑 */
			WXregister() {

			},
			/* 网页端登录逻辑，暂时不用 */
			H5register() {

			}
		}
	}
</script>

<style>
	.login-form {
		position: absolute;
		top: 5%;
		left: 0;
		right: 0;
	}
</style>
